package com.loopy.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;

public class Servlet03 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //服务器端解析第一个/时，解析成http://localhost:8080/webpath
        //http://ip:port/工程名【application context】
        System.out.println("servlet03重定向4进行转发");
//        request.getRequestDispatcher("/view/user/user.html").forward(request,response);
//        response.sendRedirect("/webpath/view/user/user.html");
//        response.sendRedirect("view/user/user.html");
        response.sendRedirect(getServletContext().getContextPath()+"/view/user/user.html");
        String realPath = getServletContext().getRealPath("/");
        String contextPath = getServletContext().getContextPath();
        System.out.println(realPath);
        System.out.println(contextPath);
    }
}
